package com.huawei.appmarket.service.appdetail.view.widget;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ScrollView;
import java.lang.ref.WeakReference;
import o.azc;
import o.Logger;
import o.drv;
import o.epv;
import o.evr;

public class DetailInnerScrollView extends ScrollView implements OnTouchListener {
    private int ʻ;
    private a ʼ;
    private c ʽ;
    private View ˊ;
    private int ˋ;
    private boolean ˋॱ;
    private int ˎ;
    private float ˏ;
    private boolean ˏॱ;
    private int ॱ;
    private b ॱˊ;
    private int ॱॱ;
    private boolean ᐝ;

    static class a extends Handler {
        WeakReference<drv> ˊ;
        WeakReference<View> ˋ;
        private int ॱ = 0;

        a(drv o_drv, View view) {
            this.ˊ = new WeakReference(o_drv);
            this.ˋ = new WeakReference(view);
        }

        public void handleMessage(Message message) {
            if (this.ˋ != null && this.ˊ != null) {
                View view = (View) this.ˋ.get();
                if (view != null && message.what == 1001) {
                    if (this.ॱ == view.getScrollY()) {
                        drv o_drv = (drv) this.ˊ.get();
                        if (o_drv != null) {
                            o_drv.ˋ(0);
                            return;
                        }
                        return;
                    }
                    sendMessageDelayed(obtainMessage(1001), 200);
                    this.ॱ = view.getScrollY();
                }
            }
        }
    }

    public interface b {
        void ˋ(int i);
    }

    static class c extends Handler {
        WeakReference<DetailInnerScrollView> ˊ;

        c(DetailInnerScrollView detailInnerScrollView) {
            this.ˊ = new WeakReference(detailInnerScrollView);
        }

        public void handleMessage(Message message) {
            DetailInnerScrollView detailInnerScrollView = (DetailInnerScrollView) this.ˊ.get();
            if (detailInnerScrollView != null) {
                detailInnerScrollView.ॱ();
                removeMessages(0);
                sendEmptyMessageDelayed(0, 5);
            }
        }
    }

    public DetailInnerScrollView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.ˏ = 0.0f;
        this.ॱ = 0;
        this.ˋ = 0;
        this.ˎ = 0;
        this.ᐝ = true;
        this.ʽ = new c(this);
        this.ॱॱ = 300;
        this.ʻ = 300;
        this.ˏॱ = false;
        this.ˋॱ = true;
        this.ʻ = epv.ॱ(getContext()) / 3;
        setOnTouchListener(this);
    }

    public void setScrollPositionListener(b bVar) {
        this.ॱˊ = bVar;
    }

    public void setStateListener(drv o_drv) {
        this.ʼ = new a(o_drv, this);
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case 1:
                if (this.ʼ != null) {
                    this.ʼ.sendMessageDelayed(this.ʼ.obtainMessage(1001), 5);
                    break;
                }
                break;
        }
        return false;
    }

    private void ॱ() {
        if (this.ˋ != 0 && this.ᐝ) {
            this.ˋ -= this.ˎ;
            if ((this.ˎ < 0 && this.ˋ > 0) || (this.ˎ > 0 && this.ˋ < 0)) {
                this.ˋ = 0;
            }
            this.ˊ.scrollTo(0, this.ˋ);
        }
    }

    protected void onFinishInflate() {
        super.onFinishInflate();
        if (getChildCount() > 0) {
            this.ˊ = getChildAt(0);
        }
        if (azc.ˎ().ॱ() < 11) {
            setOverScrollMode(2);
        }
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0) {
            this.ˏ = motionEvent.getY();
        }
        return super.onInterceptTouchEvent(motionEvent);
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        try {
            if (azc.ˎ().ॱ() < 11) {
                ॱ(motionEvent);
            }
            return super.onTouchEvent(motionEvent);
        } catch (Throwable e) {
            Logger.ˋ("InnerScrollView", "onTouchEvent error", e);
            return false;
        }
    }

    private void ॱ(MotionEvent motionEvent) {
        switch (motionEvent.getAction()) {
            case 1:
            case 3:
                if (!this.ᐝ) {
                    this.ॱ = 0;
                    this.ᐝ = true;
                    ˏ();
                    return;
                }
                return;
            case 2:
                float y = motionEvent.getY();
                int i = (int) (this.ˏ - y);
                this.ˏ = y;
                if ((!ˎ() || i >= 0) && ˋ()) {
                    this.ᐝ = false;
                    this.ˊ.scrollBy(0, (int) (((float) i) * 0.8f));
                    this.ॱ += i;
                    return;
                }
                return;
            default:
                return;
        }
    }

    private boolean ˋ() {
        if (getScrollY() == this.ˊ.getMeasuredHeight() - getHeight()) {
            return true;
        }
        return false;
    }

    public boolean ˎ() {
        return getScrollY() + this.ॱ <= 0;
    }

    protected void onScrollChanged(int i, int i2, int i3, int i4) {
        super.onScrollChanged(i, i2, i3, i4);
        evr.ˊ().ॱ(1);
        if (this.ॱˊ != null) {
            this.ॱˊ.ˋ(getScrollY());
        }
    }

    private void ˏ() {
        this.ˋ = this.ˊ.getScrollY();
        this.ˎ = this.ˋ / 50;
        this.ʽ.sendEmptyMessage(0);
    }

    protected boolean overScrollBy(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, boolean z) {
        if (azc.ˎ().ॱ() < 11) {
            return super.overScrollBy(i, i2, i3, i4, i5, i6, i7, i8, z);
        }
        boolean z2;
        int overScrollMode = getOverScrollMode();
        Object obj = computeHorizontalScrollRange() > computeHorizontalScrollExtent() ? 1 : null;
        Object obj2 = computeVerticalScrollRange() > computeVerticalScrollExtent() ? 1 : null;
        Object obj3 = (overScrollMode == 0 || (overScrollMode == 1 && obj != null)) ? 1 : null;
        obj = (overScrollMode == 0 || (overScrollMode == 1 && obj2 != null)) ? 1 : null;
        int i9 = i3 + i;
        if (obj3 == null) {
            i7 = 0;
        }
        overScrollMode = i4 + i2;
        if (obj == null) {
            this.ॱॱ = 0;
            this.ʻ = 0;
        }
        int i10 = -i7;
        int i11 = i7 + i5;
        int i12 = -this.ॱॱ;
        int i13 = this.ʻ + i6;
        if (i9 > i11) {
            i10 = i11;
            z2 = true;
        } else if (i9 < i10) {
            z2 = true;
        } else {
            z2 = false;
            i10 = i9;
        }
        boolean z3 = false;
        if (overScrollMode > i6) {
            if (!this.ˋॱ) {
                z3 = true;
                overScrollMode = i6;
            }
        } else if (overScrollMode < 0 && !this.ˏॱ) {
            overScrollMode = 0;
            z3 = true;
        }
        if (overScrollMode > i13) {
            z3 = true;
        } else if (overScrollMode < i12) {
            z3 = true;
            i13 = i12;
        } else {
            i13 = overScrollMode;
        }
        onOverScrolled(i10, i13, z2, z3);
        if (z2 || z3) {
            return true;
        }
        return false;
    }
}
